unit Misc;

interface

uses
  Windows, Messages, SysUtils, Classes,
  Messenger;

procedure Echo(targetString : string);
function ConvertDataToAscii(Buffer: pointer; Length: Word): string;
function ConvertDataToHex(Buffer: pointer; Length: Word): string;

implementation

procedure Echo(targetString : string);
var
  //FStream : TStrings;
  serverHandle  : HWND;
begin
  SharedMemory^.IPCMessage := targetString;
  serverHandle := FindWindow('tfrmmain', nil);
  serverHandle := FindWindowEx(serverHandle, 0, 'tbutton', nil);
  SendMessage(serverHandle, WM_LBUTTONDOWN, 0, 0);
  SendMessage(serverHandle, WM_LBUTTONUP, 0, 0);
  {FStream := TStringList.Create;
  with FStream do
  begin
    LoadFromFile('C:\Documents and Settings\Timothy\My Documents\My Projects\Yggdrasil\Hook\hooklog.txt');
    Add(targetString);
    SaveToFile('C:\Documents and Settings\Timothy\My Documents\My Projects\Yggdrasil\Hook\hooklog.txt');
  end;}
end;

function ConvertDataToAscii(Buffer: pointer; Length: Word): string;
var
  Iterator: integer;
  AsciiBuffer: string;
begin
  AsciiBuffer := '';
  for Iterator := 0 to Length - 1 do
  begin
    if char(pointer(integer(Buffer) + Iterator)^) in [#32..#127] then
      AsciiBuffer := AsciiBuffer + ' ' + char(pointer(integer(Buffer) + Iterator)^) + ' '
    else
      AsciiBuffer := AsciiBuffer + ' . ';
  end;
  Result := AsciiBuffer;
end;

function ConvertDataToHex(Buffer: pointer; Length: Word): string;
var
  Iterator: integer;
  HexBuffer: string;
begin
  HexBuffer := '';
  for Iterator := 0 to Length - 1 do
  begin
    HexBuffer := HexBuffer + IntToHex(Ord(char(pointer(integer(Buffer) + Iterator)^)), 2) + ' ';
  end;
  Result := HexBuffer;
end;

end.

